
const localData= localStorage.getItem('r_vuex')


const state = localData ? localData.menu:{
//左侧菜单栏是否折叠
    isCollapse:false,
    //header菜单栏tag
    menuList:[],
    routerList:[]
}
const mutations = {
    collapseMenu(state){
        state.isCollapse = !state.isCollapse
    },
    addMenu(state,payload){
        //对数据进行去重
        if (state.menuList.findIndex(item => item.path === payload.path)===-1){
            state.menuList.push(payload)
        }
    },
    closeMenu(state,payload){
        const index = state.menuList.findIndex(item => item.path === payload.path)
        state.menuList.splice(index,1)
    },
    dynamicMenu(state,payload){
        const modules=import.meta.glob('../views/**/**/*.vue')
        function routerSet(router) {
            router.forEach(route => {
                // 判断没有子菜单，拼接路由数据
                if (!route.children) {
                    const url = `../views${route.meta.path}/index.vue`;
                    route.component = modules[url]
                } else {
                    routerSet(route.children)
                }
            })
        }
        routerSet(payload)
        state.routerList = payload
    }
}
export default {
    state,
    mutations
}
